package com.xyz.service.impl;

import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.BetweenFormatter;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xyz.config.SystemData;
import com.xyz.controller.vo.NFCVo;
import com.xyz.controller.vo.ShipFlagVO;
import com.xyz.dto.PatrolTaskStateListDto;
import com.xyz.dto.PatrolTaskStateListSubDto;
import com.xyz.dto.enums.EnumPatrolState;
import com.xyz.entity.mapper.*;
import com.xyz.entity.pojo.*;
import com.xyz.service.AsyncPlanService;
import com.xyz.service.CommonService;
import com.xyz.service.PatrolService;
import com.xyz.util.ConvertVoUtil;
import com.xyz.util.DateUtils;
import com.xyz.util.dto.DataResult;
import com.xyz.util.dto.GridData;
import com.xyz.util.dto.LoginInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
@Transactional(rollbackFor = Exception.class)
public class PatrolServiceImpl implements PatrolService {

    @Autowired
    private CommonService commonService;

    @Autowired
    private SystemParameterMapper systemParameterMapper;

    @Autowired
    private BusinessFileMapper businessFileMapper;

    @Autowired
    private EquipmentInfoMapper equipmentInfoMapper;

    @Autowired
    private PatrolWorkOrderMapper patrolWorkOrderMapper;

    @Autowired
    private PatrolWorkOrderFlowMapper patrolWorkOrderFlowMapper;

    @Autowired
    private PatrolTreeMapper patrolTreeMapper;

    @Autowired
    private PatrolTreeTaskMapper patrolTreeTaskMapper;

    @Autowired
    private PatrolPlanMapper patrolPlanMapper;

    @Autowired
    private BusinessAnnounceMapper businessAnnounceMapper;

    @Autowired
    private BusinessAcceptMapper businessAcceptMapper;

    @Autowired
    private EquipmentTreeMapper equipmentTreeMapper;

    @Autowired
    private PatrolTemplateTaskMapper patrolTemplateTaskMapper;

    @Autowired
    private PatrolTemplateSubsystemMapper patrolTemplateSubsystemMapper;

    @Autowired
    private SystemFileMapper systemFileMapper;

    @Autowired
    private AsyncPlanService asyncPlanService;

    @Autowired
    private SystemEmployeeMapper systemEmployeeMapper;

    @Override
    public DataResult selectPatrol(LoginInfo li, int pageNum, int pageSize, String state, String worker, String treeId) throws Exception {
        PatrolWorkOrderExample pwoExample = new PatrolWorkOrderExample();
        PatrolWorkOrderExample.Criteria pwoCriteria = pwoExample.createCriteria();
        if (StrUtil.isNotBlank(state)) {
            List<Integer> stateList = new ArrayList<>();
            for (String stateStr : state.split(",")) {
                stateList.add(Integer.parseInt(stateStr));
            }
            pwoCriteria.andStateIn(stateList);
        }
        if ("2".equals(worker)) {
            pwoCriteria.andPatrolEmployeeIdEqualTo(li.getLoginUserId());
        }
        if (StrUtil.isNotBlank(treeId)) {
            pwoCriteria.andTreeIdEqualTo(Long.parseLong(treeId));
        }
        pwoExample.setOrderByClause("create_time desc");
        Page<PatrolWorkOrder> page = PageHelper.startPage(pageNum, pageSize);
        List<PatrolWorkOrder> pwoList = patrolWorkOrderMapper.selectByExample(pwoExample);

        Date date = new Date();
        List<Map<String, Object>> list = new ArrayList<>();
        for (PatrolWorkOrder pwo : pwoList) {
            EquipmentTree et = equipmentTreeMapper.selectByPrimaryKey(pwo.getTreeId());
            Map<String, Object> map = new HashMap<>();
            map.put("id", pwo.getId());
            map.put("code", pwo.getCode());
            map.put("state", pwo.getState());
            map.put("startDay", DateUtil.format(pwo.getStartTime(), "yyyy-MM-dd"));
            map.put("startTime", DateUtil.format(pwo.getStartTime(), "HH:mm"));
            map.put("treeId", pwo.getTreeId());
            map.put("treeName", et.getName());
            map.put("patrolEmployeeId", pwo.getPatrolEmployeeId());
            if(pwo.getPatrolEmployeeId() == 0){
                map.put("patrolEmployee", "");
            }else {
                map.put("patrolEmployee", SystemData.employeeMap.get(pwo.getPatrolEmployeeId()).getEmployeeName());
            }
            map.put("deadline", "");
            if (DateUtil.compare(pwo.getStartTime(), date) > 0 && DateUtil.compare(pwo.getStartTime(), DateUtil.offsetDay(date, 1)) < 0) {
                map.put("deadline", DateUtil.formatBetween(date, pwo.getStartTime(), BetweenFormatter.Level.SECOND));
            }
            map.put("businessType", pwo.getBusinessType());
            map.put("isOverdue", pwo.getIsOverdue());
            map.put("isAcdTimeout", pwo.getIsAcdTimeout());
            list.add(map);
        }
        return DataResult.build9100(new GridData(page.getTotal(), list));
    }

    @Override
    public DataResult selectPatrolApp(LoginInfo li, int pageNum, int pageSize, String state, String worker, String treeId, String orderCode, String strTime, String endTime) throws Exception {
        PatrolWorkOrderExample pwoExample = new PatrolWorkOrderExample();
        PatrolWorkOrderExample.Criteria pwoCriteria = pwoExample.createCriteria();
        if (StrUtil.isNotBlank(state)) {
            List<Integer> stateList = new ArrayList<>();
            for (String stateStr : state.split(",")) {
                stateList.add(Integer.parseInt(stateStr));
            }
            pwoCriteria.andStateIn(stateList);
            if(!state.equals("7")){
                pwoCriteria.andPatrolEmployeeIdEqualTo(li.getLoginEmployeeId());
            }
        }else {
            pwoCriteria.andPatrolEmployeeIdEqualTo(li.getLoginEmployeeId());
        }
        if ("2".equals(worker)) {
            pwoCriteria.andPatrolEmployeeIdEqualTo(li.getLoginUserId());
        }
        if (StrUtil.isNotBlank(treeId)) {
            pwoCriteria.andTreeIdEqualTo(Long.parseLong(treeId));
        }

        if (StrUtil.isNotBlank(orderCode)) {
            pwoCriteria.andCodeLike("%" + orderCode + "%");
        }
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        if (StrUtil.isNotBlank(strTime)) {
            pwoCriteria.andCreateTimeGreaterThanOrEqualTo(formatter.parse(strTime));
        }
        if (StrUtil.isNotBlank(endTime)) {
            pwoCriteria.andCreateTimeLessThanOrEqualTo(formatter.parse(endTime));
        }
        pwoExample.setOrderByClause("create_time desc");
        Page<PatrolWorkOrder> page = PageHelper.startPage(pageNum, pageSize);
        List<PatrolWorkOrder> pwoList = patrolWorkOrderMapper.selectByExample(pwoExample);

        Date date = new Date();
        List<Map<String, Object>> list = new ArrayList<>();
        for (PatrolWorkOrder pwo : pwoList) {
            EquipmentTree et3 = equipmentTreeMapper.selectByPrimaryKey(pwo.getTreeId());
            EquipmentTree et2 = equipmentTreeMapper.selectByPrimaryKey(et3.getBaseId());
            EquipmentTree et1 = equipmentTreeMapper.selectByPrimaryKey(et2.getBaseId());
            Map<String, Object> map = new HashMap<>();
            map.put("id", pwo.getId());
            map.put("code", pwo.getCode());
            map.put("state", pwo.getState());
            map.put("startDay", DateUtil.format(pwo.getStartTime(), "yyyy-MM-dd"));
            map.put("startTime", DateUtil.format(pwo.getStartTime(), "HH:mm"));
            map.put("treeId", pwo.getTreeId());
            map.put("treeAreaName", et1.getName());
            map.put("treeSystemName", et2.getName());
            map.put("treeName", et3.getName());
            map.put("patrolEmployeeId", pwo.getPatrolEmployeeId());
            if(pwo.getPatrolEmployeeId() == 0){
                map.put("patrolEmployee", "");
            }else {
                map.put("patrolEmployee", SystemData.employeeMap.get(pwo.getPatrolEmployeeId()).getEmployeeName());
            }
            map.put("deadline", "");
            if (DateUtil.compare(pwo.getStartTime(), date) > 0 && DateUtil.compare(pwo.getStartTime(), DateUtil.offsetDay(date, 1)) < 0) {
                map.put("deadline", DateUtil.formatBetween(date, pwo.getStartTime(), BetweenFormatter.Level.SECOND));
            }
            map.put("businessType", pwo.getBusinessType());
            map.put("endTime", DateUtil.format(pwo.getEndTime(), "yyyy-MM-dd HH:mm"));
            list.add(map);
        }
        return DataResult.build9100(new GridData(page.getTotal(), list));
    }

    @Override
    public DataResult selectPatrolOne(LoginInfo li, long id) throws Exception {
        Date date = new Date();
        PatrolWorkOrder pwo = patrolWorkOrderMapper.selectByPrimaryKey(id);
        if (pwo == null) {
            return DataResult.build9404();
        }

        EquipmentTree et = equipmentTreeMapper.selectByPrimaryKey(pwo.getTreeId());
        Map<String, Object> map = new HashMap<>();
        map.put("id", pwo.getId());
        map.put("code", pwo.getCode());
        map.put("state", pwo.getState());
        map.put("startDay", DateUtil.format(pwo.getStartTime(), "yyyy-MM-dd"));
        map.put("startTime", DateUtil.format(pwo.getStartTime(), "HH:mm"));
        map.put("treeId", pwo.getTreeId());
        map.put("treeName", et.getName());
        map.put("skipFlag", pwo.getSkipFlag() == null ? "N": pwo.getSkipFlag());
        map.put("teamGroup", pwo.getTeamGroup() == null ? null : Integer.parseInt(pwo.getTeamGroup()));
        if(pwo.getPatrolEmployeeId() == 0){
            map.put("patrolEmployee", "");
        }else {
            map.put("patrolEmployee", SystemData.employeeMap.get(pwo.getPatrolEmployeeId()).getEmployeeName());
        }
        map.put("deadline", "");
        if (DateUtil.compare(pwo.getStartTime(), date) > 0 && DateUtil.compare(pwo.getStartTime(), DateUtil.offsetDay(date, 1)) < 0) {
            map.put("deadline", DateUtil.formatBetween(date, pwo.getStartTime(), BetweenFormatter.Level.SECOND));
        }
        map.put("businessType", pwo.getBusinessType());

        return DataResult.build9100(map);
    }

    @Override
    public DataResult updateSkipFlag(LoginInfo li, ShipFlagVO shipFlagVO) throws Exception{
        if (shipFlagVO == null || shipFlagVO.getId() == null || shipFlagVO.getId() == 0L) {
            return DataResult.build9404();
        }
        PatrolWorkOrder pwo = patrolWorkOrderMapper.selectByPrimaryKey(shipFlagVO.getId());
        if (pwo == null) {
            return DataResult.build9404();
        }
        if (shipFlagVO.getSkipFlag() == null || !shipFlagVO.getSkipFlag().equals("Y")){
            shipFlagVO.setSkipFlag("N");
        }
        pwo.setSkipFlag(shipFlagVO.getSkipFlag());

        patrolWorkOrderMapper.updateByPrimaryKey(pwo);
        return DataResult.build9100();
    }


    @Override
    public DataResult selectNFCPatrolOne(LoginInfo li, NFCVo nfcVo){
        PatrolWorkOrder pwo = patrolWorkOrderMapper.selectByPrimaryKey(nfcVo.getId());
        EquipmentInfo equipmentInfo = equipmentInfoMapper.selectByCode(nfcVo.getCode());
        if (pwo == null || equipmentInfo == null) {
            return DataResult.build9404();
        }
        if (pwo.getState() != 2) {
            return DataResult.build8100();
        }
        if(pwo.getSkipFlag() != null && pwo.getSkipFlag().equals("Y")){
            return DataResult.build9100();
        }
        if(pwo.getPatrolEmployeeId() == null){
            return DataResult.build8101();
        }
        if(!pwo.getPatrolEmployeeId().equals(li.getLoginEmployeeId())){
            return DataResult.build8102();
        }
        if(pwo.getTreeId() == null){
            return DataResult.build8103();
        }
        if(!pwo.getTreeId().equals(equipmentInfo.getSubTreeId())){
            return DataResult.build8104();
        }
        return DataResult.build9100();

    }


    @Override
    public DataResult insertPatrol(LoginInfo li, String startDay, String startTime,
                                   long treeId, long patrolEmployeeId) throws Exception {
        Date date = new Date();
        PatrolWorkOrder newPwo = new PatrolWorkOrder();
        SystemEmployee systemEmployee = systemEmployeeMapper.selectByPrimaryKey(patrolEmployeeId);
        if(systemEmployee == null){
            return DataResult.build9404();
        }
        newPwo.setCode(commonService.getPatrolCode());
        newPwo.setTreeId(treeId);
        newPwo.setState(EnumPatrolState.ALLOCATED.getState());
        newPwo.setStartTime(DateUtil.parseDateTime(startDay + " " + startTime + ":00"));
        newPwo.setIsException(0);
        newPwo.setCreateEmployeeId(li.getLoginEmployeeId());
        newPwo.setPatrolEmployeeId(patrolEmployeeId);
        newPwo.setCreateTime(date);
        newPwo.setAssStartTime(date);
        newPwo.setBusinessType(1);
        newPwo.setPlanId(0L);
        newPwo.setSkipFlag("N");
        newPwo.setTeamGroup(systemEmployee.getTeamGroup());
        patrolWorkOrderMapper.insertSelective(newPwo);

        insertFlow(newPwo.getId(), 1, 0, li.getLoginEmployeeId(), "", date);

        insertFlow(newPwo.getId(), 8, 0, patrolEmployeeId, "", date);

        insertTask(newPwo.getId(), treeId);

        EquipmentTree tree3 = equipmentTreeMapper.selectByPrimaryKey(treeId);
        EquipmentTree tree2 = equipmentTreeMapper.selectByPrimaryKey(tree3.getBaseId());
        EquipmentTree tree1 = equipmentTreeMapper.selectByPrimaryKey(tree2.getBaseId());

        commonService.insertMessageBacklog(
                patrolEmployeeId,
                "【" + newPwo.getCode() + "】巡检单已分配到您，请处理",
                "【" + newPwo.getCode() + "】已分配到您，巡检区域：【" + tree1.getName() + "-" + tree2.getName() + "-" + tree3.getName() + "】，请尽快到场处理。",
                4, 1, newPwo.getId(), newPwo.getCode()
        );

        return DataResult.build9100(newPwo.getId());
    }

    @Override
    public DataResult updatePatrol(LoginInfo li, long id, String startDay, String startTime, long treeId, long patrolEmployeeId) throws Exception {
        PatrolWorkOrder pwo = patrolWorkOrderMapper.selectByPrimaryKey(id);
        if (pwo.getState() != 1) {
            return DataResult.build9250("巡检单当前状态已不可编辑");
        }
        PatrolWorkOrder newPwo = new PatrolWorkOrder();
        newPwo.setId(id);
        newPwo.setTreeId(treeId);
        newPwo.setStartTime(DateUtil.parseDateTime(startDay + " " + startTime + ":00"));
        newPwo.setPatrolEmployeeId(patrolEmployeeId);
        patrolWorkOrderMapper.updateByPrimaryKeySelective(newPwo);

        if (pwo.getTreeId() != treeId) {
            PatrolTreeExample ptExample = new PatrolTreeExample();
            ptExample.createCriteria().andPatrolIdEqualTo(id);
            patrolTreeMapper.deleteByExample(ptExample);
            insertTask(newPwo.getId(), treeId);
        }

        return DataResult.build9100();
    }

    @Override
    public DataResult deletePatrol(LoginInfo li, long id) throws Exception {
        PatrolWorkOrder pwo = patrolWorkOrderMapper.selectByPrimaryKey(id);
        if (pwo.getState() != 1) {
            return DataResult.build9250("巡检单当前状态已不可编辑");
        }
        patrolWorkOrderMapper.deleteByPrimaryKey(id);
        return DataResult.build9100();
    }

    @Override
    public DataResult selectPatrolTaskPreview(LoginInfo li, long id) throws Exception {
        Map<Integer, String> emTypeMap = commonService.getDictMap("TYPE_EM_TYPE");
        List<Map<String, Object>> list = new ArrayList<>();

        EquipmentTreeExample etExample = new EquipmentTreeExample();
        etExample.createCriteria().andBaseIdEqualTo(id);
        etExample.setOrderByClause("sort");
        List<EquipmentTree> etList = equipmentTreeMapper.selectByExample(etExample);
        for (EquipmentTree et : etList) {
            if (et.getEmType() == 0) {
                continue;
            }
            PatrolTemplateTaskExample pttExample = new PatrolTemplateTaskExample();
            pttExample.createCriteria().andTypeEqualTo(1).andEmTypeEqualTo(et.getEmType());
            pttExample.setOrderByClause("sort");
            List<PatrolTemplateTask> pttList = patrolTemplateTaskMapper.selectByExample(pttExample);
            List<Map<String, Object>> taskList = new ArrayList<>();
            for (PatrolTemplateTask ptt : pttList) {
                Map<String, Object> taskMap = new HashMap<>();
                taskMap.put("id", ptt.getId());
                taskMap.put("isRecorded", ptt.getIsRecorded());
                taskMap.put("project", ptt.getProject());
                taskMap.put("way", ptt.getWay());
                taskMap.put("standard", ptt.getStandard());
                taskList.add(taskMap);
            }
            if (taskList.size() != 0) {
                Map<String, Object> map = new HashMap<>();
                map.put("id", et.getId());
                map.put("type", 1);
                map.put("emTypeName", emTypeMap.get(et.getEmType()));
                map.put("name", et.getName());
                map.put("code", et.getCode());
                map.put("taskList", taskList);
                list.add(map);
            }
        }
        EquipmentInfoExample eiExample = new EquipmentInfoExample();
        eiExample.createCriteria().andEmTreeEqualTo(id).andEmTypeNotEqualTo(0);
        List<EquipmentInfo> eiList = equipmentInfoMapper.selectByExample(eiExample);
        for (EquipmentInfo ei : eiList) {
            PatrolTemplateTaskExample pttExample = new PatrolTemplateTaskExample();
            pttExample.createCriteria().andTypeEqualTo(1).andEmTypeEqualTo(ei.getEmType());
            pttExample.setOrderByClause("sort");
            List<PatrolTemplateTask> pttList = patrolTemplateTaskMapper.selectByExample(pttExample);
            List<Map<String, Object>> taskList = new ArrayList<>();
            for (PatrolTemplateTask ptt : pttList) {
                Map<String, Object> taskMap = new HashMap<>();
                taskMap.put("id", ptt.getId());
                taskMap.put("isRecorded", ptt.getIsRecorded());
                taskMap.put("project", ptt.getProject());
                taskMap.put("way", ptt.getWay());
                taskMap.put("standard", ptt.getStandard());
                taskList.add(taskMap);
            }
            if (taskList.size() != 0) {
                Map<String, Object> map = new HashMap<>();
                map.put("id", ei.getId());
                map.put("type", 2);
                map.put("emTypeName", emTypeMap.get(ei.getEmType()));
                map.put("name", ei.getEmName());
                map.put("code", ei.getEmCode());
                map.put("taskList", taskList);
                list.add(map);
            }
        }
        PatrolTemplateSubsystemExample subsystemExample = new PatrolTemplateSubsystemExample();
        subsystemExample.createCriteria().andSubsystemTreeIdEqualTo(id);
        List<PatrolTemplateSubsystem> patrolTemplateSubsystems = patrolTemplateSubsystemMapper.selectByExample(subsystemExample);
        for (PatrolTemplateSubsystem patrolTemplateSubsystem : patrolTemplateSubsystems) {
            PatrolTemplateTaskExample pttExample = new PatrolTemplateTaskExample();
            pttExample.createCriteria().andTypeEqualTo(2).andSubsystemIdEqualTo(patrolTemplateSubsystem.getId());
            pttExample.setOrderByClause("sort");
            List<PatrolTemplateTask> pttList = patrolTemplateTaskMapper.selectByExample(pttExample);
            List<Map<String, Object>> taskList = new ArrayList<>();
            for (PatrolTemplateTask ptt : pttList) {
                Map<String, Object> taskMap = new HashMap<>();
                taskMap.put("id", ptt.getId());
                taskMap.put("isRecorded", ptt.getIsRecorded());
                taskMap.put("project", ptt.getProject());
                taskMap.put("way", ptt.getWay());
                taskMap.put("standard", ptt.getStandard());
                taskList.add(taskMap);
            }
            if (taskList.size() != 0) {
                Map<String, Object> map = new HashMap<>();
                map.put("id", patrolTemplateSubsystem.getId());
                map.put("type", 3);
                map.put("emTypeName", patrolTemplateSubsystem.getName());
                map.put("name", "");
                map.put("code", "");
                map.put("taskList", taskList);
                list.add(map);
            }
        }
        return DataResult.build9100(list);
    }

    @Override
    public DataResult selectPatrolTask(LoginInfo li, long id) throws Exception {
        PatrolWorkOrder pwo = patrolWorkOrderMapper.selectByPrimaryKey(id);
        Map<Integer, String> emTypeMap = commonService.getDictMap("TYPE_EM_TYPE");
        Map<Long, PatrolTemplateTask> ttiMap = CollStreamUtil.toIdentityMap(patrolTemplateTaskMapper.selectByExample(null), PatrolTemplateTask::getId);

        PatrolTreeExample ptExample = new PatrolTreeExample();
        ptExample.createCriteria().andPatrolIdEqualTo(pwo.getId());
        ptExample.setOrderByClause("sort");
        List<PatrolTree> ptList = patrolTreeMapper.selectByExample(ptExample);
        List<Map<String, Object>> list = new ArrayList<>();
        for (PatrolTree pt : ptList) {

            PatrolTreeTaskExample pttExample = new PatrolTreeTaskExample();
            pttExample.createCriteria().andPatrolTreeIdEqualTo(pt.getId());
            pttExample.setOrderByClause("sort");
            List<PatrolTreeTask> pttList = patrolTreeTaskMapper.selectByExample(pttExample);

            List<Map<String, Object>> taskList = new ArrayList<>();
            for (PatrolTreeTask ptt : pttList) {
                PatrolTemplateTask tt = ttiMap.get(ptt.getTaskId());
                Map<String, Object> taskMap = new HashMap<>();
                taskMap.put("id", ptt.getId());
                taskMap.put("state", ptt.getState());
                taskMap.put("isRecorded", ptt.getIsRecorded());
                taskMap.put("recordedValue", ptt.getRecordedValue());
                if(tt != null){
                    taskMap.put("project", tt.getProject());
                    taskMap.put("way", tt.getWay());
                    taskMap.put("standard", tt.getStandard());
                }else {
                    taskMap.put("project", "");
                    taskMap.put("way", "");
                    taskMap.put("standard", "");
                }
                taskList.add(taskMap);
            }
            if (!taskList.isEmpty()) {
                Map<String, Object> map = new HashMap<>();
                map.put("id", pt.getId());
                map.put("type", pt.getType());
                if(pt.getType() == 1 || pt.getType() == 2){
                    map.put("emTypeName", emTypeMap.get(pt.getEmType()));
                    if (pt.getType() == 1) {
                        EquipmentTree equipmentTree = equipmentTreeMapper.selectByPrimaryKey(pt.getTypeId());
                        map.put("name", equipmentTree.getName());
                        map.put("code", equipmentTree.getCode());
                    } else {
                        EquipmentInfo equipmentInfo = equipmentInfoMapper.selectByPrimaryKey(pt.getTypeId());
                        map.put("name", equipmentInfo.getEmName());
                        map.put("code", equipmentInfo.getEmCode());
                    }
                }else {
                    PatrolTemplateSubsystem patrolTemplateSubsystem = patrolTemplateSubsystemMapper.selectByPrimaryKey(pt.getTypeId());
                    if(patrolTemplateSubsystem != null){
                        map.put("emTypeName", patrolTemplateSubsystem.getName());
                    }else {
                        map.put("emTypeName", "");
                    }
                    map.put("name", "");
                    map.put("code", "");
                }

                map.put("state", pt.getState());
                map.put("taskList", taskList);
                list.add(map);
            }
        }
        return DataResult.build9100(list);
    }

    @Override
    public DataResult selectPatrolPlan(LoginInfo li, int pageNum, int pageSize, String treeId, String businessType, String state) throws Exception {
        PatrolPlanExample ppExample = new PatrolPlanExample();
        PatrolPlanExample.Criteria ppCriteria = ppExample.createCriteria();
        if (StrUtil.isNotBlank(treeId)) {
            ppCriteria.andEmTreeEqualTo(Long.parseLong(treeId));
        }
        if (StrUtil.isNotBlank(businessType)) {
            ppCriteria.andBusinessTypeEqualTo(Integer.parseInt(businessType));
        }
        if (StrUtil.isNotBlank(state)) {
            ppCriteria.andStateEqualTo(Integer.parseInt(state));
        }
        ppExample.setOrderByClause("create_time desc");
        Page<PatrolPlan> page = PageHelper.startPage(pageNum, pageSize);
        List<PatrolPlan> ppList = patrolPlanMapper.selectByExample(ppExample);

        List<EquipmentTree> etList = equipmentTreeMapper.selectByExample(null);
        Map<Long, EquipmentTree> etMap = CollStreamUtil.toIdentityMap(etList, EquipmentTree::getId);

        List<Map<String, Object>> list = new ArrayList<>();
        for (PatrolPlan pp : ppList) {
            Map<String, Object> map = new HashMap<>();
            map.put("id", pp.getId());
            map.put("planName", pp.getPlanName());
            map.put("businessType", pp.getBusinessType());
            map.put("dateInterval", pp.getDateInterval());
            map.put("planStartTime", DateUtil.formatDate(pp.getPlanStartTime()));
            map.put("planEndTime", DateUtil.formatDate(pp.getPlanEndTime()));
            map.put("firstTime", DateUtil.formatDateTime(pp.getFirstTime()));
            map.put("state", pp.getState());
            map.put("treeId", pp.getEmTree());
            map.put("treeName", etMap.get(pp.getEmTree()).getName());
            map.put("createTime", DateUtil.formatDateTime(pp.getCreateTime()));
            map.put("teamGroup", pp.getTeamGroup() == null ? null : Integer.parseInt(pp.getTeamGroup()));
            list.add(map);
        }
        return DataResult.build9100(new GridData(page.getTotal(), list));
    }

    @Override
    public DataResult selectPatrolPlanOne(LoginInfo li, long id) throws Exception {
        PatrolPlan pp = patrolPlanMapper.selectByPrimaryKey(id);
        EquipmentTree et = equipmentTreeMapper.selectByPrimaryKey(pp.getEmTree());
        Map<String, Object> map = new HashMap<>();
        map.put("id", pp.getId());
        map.put("planName", pp.getPlanName());
        map.put("businessType", pp.getBusinessType());
        map.put("dateInterval", pp.getDateInterval());
        map.put("planStartTime", DateUtil.formatDate(pp.getPlanStartTime()));
        map.put("planEndTime", DateUtil.formatDate(pp.getPlanEndTime()));
        map.put("firstTime", DateUtil.formatDateTime(pp.getFirstTime()));
        map.put("state", pp.getState());
        map.put("treeId", pp.getEmTree());
        map.put("treeName", et.getName());
        map.put("createTime", DateUtil.formatDateTime(pp.getCreateTime()));
        map.put("teamGroup", pp.getTeamGroup() == null ? null : Integer.parseInt(pp.getTeamGroup()));
        return DataResult.build9100(map);

    }

    @Override
    public DataResult insertPatrolPlan(LoginInfo li, String planName, int businessType,
                                       int dateInterval, Date planStartTime, Date planEndTime,
                                       Date firstTime, long treeId,String teamGroup) throws Exception {
        Date date = new Date();
        PatrolPlan newPp = new PatrolPlan();
        newPp.setPlanName(planName);
        newPp.setBusinessType(businessType);
        newPp.setDateInterval(dateInterval);
        newPp.setPlanStartTime(planStartTime);
        newPp.setPlanEndTime(planEndTime);
        newPp.setFirstTime(firstTime);
        newPp.setState(1);
        newPp.setEmTree(treeId);
        newPp.setUpdateTime(date);
        newPp.setCreateTime(date);
        newPp.setTeamGroup(teamGroup);
        patrolPlanMapper.insert(newPp);
        return DataResult.build9100(newPp.getId());
    }

    @Override
    public DataResult updatePatrolPlan(LoginInfo li, long id, String planName, int businessType, int dateInterval,
                                       Date planStartTime, Date planEndTime, Date firstTime, long treeId, int state,String teamGroup) throws Exception {
        PatrolPlan patrolPlan = patrolPlanMapper.selectByPrimaryKey(id);
        //状态：1草稿；2已启用；3已停用；4已作废
        if (state == 2) {
            if (patrolPlan.getState() != 1 && patrolPlan.getState() != 4) {
                return DataResult.build9250("草稿状态才能启用！");
            }
        } else if (state == 3) {
            if (patrolPlan.getState() != 2) {
                return DataResult.build9250("启用状态才能停用！");
            }
        } else if (state == 4) {
            if (patrolPlan.getState() != 3) {
                return DataResult.build9250("停用状态才能作废！");
            }
        }

        Date date = new Date();
        PatrolPlan newPp = new PatrolPlan();
        newPp.setId(id);
        newPp.setPlanName(planName);
        newPp.setBusinessType(businessType);
        newPp.setDateInterval(dateInterval);
        newPp.setPlanStartTime(planStartTime);
        newPp.setPlanEndTime(planEndTime);
        newPp.setFirstTime(firstTime);
        newPp.setState(state);
        newPp.setEmTree(treeId);
        newPp.setUpdateTime(date);
        newPp.setTeamGroup(teamGroup);
        patrolPlanMapper.updateByPrimaryKeySelective(newPp);
        //异步生成或删除计划
        asyncPlanService.insertPlanInfoByPatrol(newPp);
        return DataResult.build9100();
    }

    @Override
    public DataResult deletePatrolPlan(LoginInfo li, long id) throws Exception {
        PatrolPlan patrolPlan = patrolPlanMapper.selectByPrimaryKey(id);
        //状态：1草稿；2已启用；3已停用；4已作废
        if (patrolPlan.getState() != 1 && patrolPlan.getState() != 4) {
            return DataResult.build9250("草稿或作废状态才能删除！");
        }
        patrolPlanMapper.deleteByPrimaryKey(id);
        return DataResult.build9100();
    }

    @Override
    public DataResult selectPatrolAnnounce(LoginInfo li, long id) throws Exception {
        BusinessAnnounceExample baExample = new BusinessAnnounceExample();
        baExample.createCriteria().andBusTypeEqualTo(5).andSourceIdEqualTo(id);
        baExample.setOrderByClause("create_time desc");
        List<BusinessAnnounce> baList = businessAnnounceMapper.selectByExample(baExample);
        PatrolWorkOrder patrolWorkOrder = patrolWorkOrderMapper.selectByPrimaryKey(id);
        Map<String, Object> map = new HashMap<>();
        if (baList.size() > 0 && patrolWorkOrder.getState().equals(EnumPatrolState.MAINTENANCE_YES.getState())) {
            BusinessAnnounce ba = baList.get(0);
            map.put("annState", ba.getAnnState());
            map.put("employeeName", SystemData.employeeMap.get(ba.getEmployeeId()).getEmployeeName());
            map.put("annExplain", ba.getAnnExplain());
            map.put("annTime", DateUtil.formatDateTime(ba.getAnnTime()));
        } else {
            map.put("annState", null);
            map.put("EmployeeName", null);
            map.put("annExplain", null);
            map.put("annTime", null);
        }
        return DataResult.build9100(map);
    }

    @Override
    public DataResult selectPatrolFlow(LoginInfo li, long id) throws Exception {
        PatrolWorkOrderFlowExample pwofExample = new PatrolWorkOrderFlowExample();
        pwofExample.createCriteria().andPatrolIdEqualTo(id);
        pwofExample.setOrderByClause("create_time desc,flow_type");
        List<PatrolWorkOrderFlow> pwofList = patrolWorkOrderFlowMapper.selectByExample(pwofExample);

        List<Map<String, Object>> list = new ArrayList<>();
        for (PatrolWorkOrderFlow pwof : pwofList) {
            Map<String, Object> map = new HashMap<>();
            map.put("id", pwof.getId());
            if(pwof.getEmployeeId() == 0){
                map.put("employeeName", "系统自动生成");
            }else {
                map.put("employeeName", SystemData.employeeMap.get(pwof.getEmployeeId()).getEmployeeName());
            }
            map.put("flowDesc", pwof.getFlowDesc());
            map.put("time", DateUtil.formatDateTime(pwof.getCreateTime()));
            if (pwof.getFlowType() == -1) {
                map.put("flowType", "巡检单失效");
            } else if (pwof.getFlowType() == 1) {
                map.put("flowType", "巡检单新增");
            } else if (pwof.getFlowType() == 2) {
                map.put("flowType", "巡检单审核");
            } else if (pwof.getFlowType() == 3) {
                map.put("flowType", "巡检单开工");
            } else if (pwof.getFlowType() == 4) {
                map.put("flowType", "巡检单完工");
            } else if (pwof.getFlowType() == 5) {
                map.put("flowType", "巡检单验收通过");
            } else if (pwof.getFlowType() == 6) {
                map.put("flowType", "巡检单暂停");
            } else if (pwof.getFlowType() == 7) {
                map.put("flowType", "巡检单验收驳回");
            } else if (pwof.getFlowType() == 8) {
                map.put("flowType", "领取工单");
            } else if (pwof.getFlowType() == 9) {
                map.put("flowType", "工单转交");
            }  else if (pwof.getFlowType() == 10) {
                map.put("flowType", "工单作废");
            }else {
                map.put("flowType", "");
            }
            list.add(map);
        }
        return DataResult.build9100(list);
    }

    @Override
    public DataResult selectPatrolDetail(LoginInfo li, long id) throws Exception {
        PatrolWorkOrder pwo = patrolWorkOrderMapper.selectByPrimaryKey(id);
        Map<String, Object> map = new HashMap<>();
        map.put("id", pwo.getId());
        map.put("endTime", pwo.getEndTime() == null ? null : DateUtil.formatDateTime(pwo.getEndTime()));
        map.put("orderDuration", pwo.getOrderDuration() == null ? null : (pwo.getOrderDuration() / 60) + "小时" + (pwo.getOrderDuration() % 60) + "分");
        map.put("orderWorkHour", pwo.getOrderWorkHour() == null ? null : (pwo.getOrderWorkHour() / 60) + "小时" + (pwo.getOrderWorkHour() % 60) + "分");
        map.put("orderException", pwo.getOrderException());

        List<Map<String, String>> filePicCode = new ArrayList<>();
        List<Map<String, String>> fileAudioCode = new ArrayList<>();
        List<Map<String, String>> fileVideoCode = new ArrayList<>();

        BusinessFileExample bfExample = new BusinessFileExample();
        bfExample.createCriteria().andBusTypeEqualTo(8).andFileGroupEqualTo(1).andBusTablesIdEqualTo(pwo.getId());
        List<BusinessFile> bfList = businessFileMapper.selectByExample(bfExample);

        if (bfList.size() > 0) {
            SystemFileExample sfExample = new SystemFileExample();
            sfExample.createCriteria().andFileCodeIn(CollStreamUtil.toList(bfList, BusinessFile::getFileCode));
            List<SystemFile> systemFiles1 = systemFileMapper.selectByExample(sfExample);
            Map<String, SystemFile> fileMap1 = CollStreamUtil.toIdentityMap(systemFiles1, SystemFile::getFileCode);

            for (BusinessFile bf : bfList) {
                Map<String, String> fileMap = new HashMap<>();
                fileMap.put("fileCode", bf.getFileCode());
                fileMap.put("fileName", fileMap1.get(bf.getFileCode()).getFileName());
                if (bf.getFileType() == 1) {
                    filePicCode.add(fileMap);
                } else if (bf.getFileType() == 2) {
                    fileAudioCode.add(fileMap);
                } else if (bf.getFileType() == 3) {
                    fileVideoCode.add(fileMap);
                }
            }
        }

        map.put("filePicCode", filePicCode);
        map.put("fileAudioCode", fileAudioCode);
        map.put("fileVideoCode", fileVideoCode);
        return DataResult.build9100(map);
    }

    @Override
    public DataResult selectPatrolDispose(LoginInfo li, long id) throws Exception {
        PatrolWorkOrder pwo = patrolWorkOrderMapper.selectByPrimaryKey(id);
        Map<String, Object> map = new HashMap<>();
        map.put("id", pwo.getId());
        map.put("patrolEmployeeId", pwo.getPatrolEmployeeId());
        if(pwo.getPatrolEmployeeId() == 0){
            map.put("patrolEmployee", "");
        }else {
            map.put("patrolEmployee", SystemData.employeeMap.get(pwo.getPatrolEmployeeId()).getEmployeeName());
        }
        map.put("faultType", pwo.getFaultType());
        map.put("faultReason", pwo.getFaultReason());
        map.put("emState", pwo.getEmState());
        map.put("disposeResult", pwo.getDisposeResult());

        List<Map<String, String>> fileOldPicCode = new ArrayList<>();
        List<Map<String, String>> fileOldAudioCode = new ArrayList<>();
        List<Map<String, String>> fileOldVideoCode = new ArrayList<>();
        BusinessFileExample bfExample = new BusinessFileExample();
        bfExample.createCriteria().andBusTypeEqualTo(8).andFileGroupEqualTo(2).andBusTablesIdEqualTo(pwo.getId());
        List<BusinessFile> bfList1 = businessFileMapper.selectByExample(bfExample);
        if (bfList1.size() > 0) {
            SystemFileExample sfExample = new SystemFileExample();
            sfExample.createCriteria().andFileCodeIn(CollStreamUtil.toList(bfList1, BusinessFile::getFileCode));
            List<SystemFile> systemFiles1 = systemFileMapper.selectByExample(sfExample);
            Map<String, SystemFile> fileMap1 = CollStreamUtil.toIdentityMap(systemFiles1, SystemFile::getFileCode);

            for (BusinessFile bf : bfList1) {
                Map<String, String> fileMap = new HashMap<>();
                fileMap.put("fileCode", bf.getFileCode());
                fileMap.put("fileName", fileMap1.get(bf.getFileCode()).getFileName());
                if (bf.getFileType() == 1) {
                    fileOldPicCode.add(fileMap);
                } else if (bf.getFileType() == 2) {
                    fileOldAudioCode.add(fileMap);
                } else if (bf.getFileType() == 3) {
                    fileOldVideoCode.add(fileMap);
                }
            }
        }

        List<Map<String, String>> fileNewPicCode = new ArrayList<>();
        List<Map<String, String>> fileNewAudioCode = new ArrayList<>();
        List<Map<String, String>> fileNewVideoCode = new ArrayList<>();
        bfExample.clear();
        bfExample.createCriteria().andBusTypeEqualTo(8).andFileGroupEqualTo(3).andBusTablesIdEqualTo(pwo.getId());
        List<BusinessFile> bfList2 = businessFileMapper.selectByExample(bfExample);
        if (bfList2.size() > 0) {
            SystemFileExample sfExample = new SystemFileExample();
            sfExample.createCriteria().andFileCodeIn(CollStreamUtil.toList(bfList1, BusinessFile::getFileCode));
            List<SystemFile> systemFiles1 = systemFileMapper.selectByExample(sfExample);
            Map<String, SystemFile> fileMap1 = CollStreamUtil.toIdentityMap(systemFiles1, SystemFile::getFileCode);
            for (BusinessFile bf : bfList2) {
                Map<String, String> fileMap = new HashMap<>();
                fileMap.put("fileCode", bf.getFileCode());
                fileMap.put("fileName", fileMap1.get(bf.getFileCode()).getFileName());
                if (bf.getFileType() == 1) {
                    fileNewPicCode.add(fileMap);
                } else if (bf.getFileType() == 2) {
                    fileNewAudioCode.add(fileMap);
                } else if (bf.getFileType() == 3) {
                    fileNewVideoCode.add(fileMap);
                }
            }
        }

        map.put("fileOldPicCode", fileOldPicCode);
        map.put("fileOldAudioCode", fileOldAudioCode);
        map.put("fileOldVideoCode", fileOldVideoCode);
        map.put("fileNewPicCode", fileNewPicCode);
        map.put("fileNewAudioCode", fileNewAudioCode);
        map.put("fileNewVideoCode", fileNewVideoCode);
        return DataResult.build9100(map);
    }

    @Override
    public DataResult selectPatrolAccept(LoginInfo li, long id) throws Exception {
        BusinessAcceptExample baExample = new BusinessAcceptExample();
        baExample.createCriteria().andBusTypeEqualTo(5).andSourceIdEqualTo(id);
        List<BusinessAccept> baList = businessAcceptMapper.selectByExample(baExample);
        Map<String, Object> map = new HashMap<>();
        if (baList.size() > 0) {
            BusinessAccept ba = baList.get(0);
            map.put("acceptState", ba.getAcceptState());
            map.put("employeeName", SystemData.employeeMap.get(ba.getEmployeeId()).getEmployeeName());
            map.put("acceptExplain", ba.getAcceptExplain());
            map.put("acceptScore", ba.getAcceptScore());
            map.put("acceptTime", DateUtil.formatDateTime(ba.getAcceptTime()));
        } else {
            map.put("acceptState", null);
            map.put("employeeName", null);
            map.put("acceptExplain", null);
            map.put("acceptScore", null);
            map.put("acceptTime", null);
        }
        return DataResult.build9100(map);
    }

    @Override
    public DataResult updatePatrolState(LoginInfo li, long id, int operation, String operationInfo, String acceptScore, String acceptState) throws Exception {
        PatrolWorkOrder pwo = patrolWorkOrderMapper.selectByPrimaryKey(id);
        if (pwo.getState().equals(EnumPatrolState.MAINTENANCE_YES.getState())) {
            return DataResult.build9250("巡检单当前状态已不可编辑");
        }
        Date date = new Date();
        // operation：-1审核驳回，2审核通过，3巡检开工，4巡检完成，5验收，6暂停
        // state：-1失效，1待审核，2待巡检，3巡检中，4待验收，5已完成，6暂停，7待领取
        int state = pwo.getState();
        if (operation == -1) {
            /*if (pwo.getState() != 1) {
                return DataResult.build9250("巡检单当前状态已不可审核");
            }
            BusinessAnnounce newBa = new BusinessAnnounce();
            newBa.setSourceId(id);
            newBa.setBusType(5);
            newBa.setAnnState(1);
            newBa.setEmployeeId(li.getLoginEmployeeId());
            newBa.setAnnExplain(StrUtil.isBlank(operationInfo) ? "" : operationInfo);
            newBa.setAnnTime(date);
            newBa.setCreateTime(date);
            businessAnnounceMapper.insert(newBa);

            insertFlow(id, -1, newBa.getId(), li.getLoginEmployeeId(), StrUtil.isBlank(operationInfo) ? "" : operationInfo, date);
*/
        } else if (operation == 2) {
            /*if (pwo.getState() != 1) {
                return DataResult.build9250("巡检单当前状态已不可审核");
            }
            BusinessAnnounce newBa = new BusinessAnnounce();
            newBa.setSourceId(id);
            newBa.setBusType(5);
            newBa.setAnnState(2);
            newBa.setEmployeeId(li.getLoginEmployeeId());
            newBa.setAnnExplain(StrUtil.isBlank(operationInfo) ? "" : operationInfo);
            newBa.setAnnTime(date);
            newBa.setCreateTime(date);
            businessAnnounceMapper.insert(newBa);

            insertFlow(id, 2, newBa.getId(), li.getLoginEmployeeId(), StrUtil.isBlank(operationInfo) ? "" : operationInfo, date);

            EquipmentTree tree3 = equipmentTreeMapper.selectByPrimaryKey(pwo.getTreeId());
            EquipmentTree tree2 = equipmentTreeMapper.selectByPrimaryKey(tree3.getBaseId());
            EquipmentTree tree1 = equipmentTreeMapper.selectByPrimaryKey(tree2.getBaseId());
            commonService.insertMessageBacklog(
                    pwo.getPatrolEmployeeId(),
                    "巡检单【" + pwo.getCode() + "】巡检单已安排到您，请处理",
                    "巡检单【" + pwo.getCode() + "】已安排到您，地点在【" + tree1.getName() + "-" + tree2.getName() + "-" + tree3.getName() + "】，请尽快到场处理。",
                    4, 2, pwo.getId(), pwo.getCode()
            );
*/
        } else if (operation == 3) {
            if (pwo.getState().equals(EnumPatrolState.ALLOCATED.getState()) || pwo.getState().equals(EnumPatrolState.SUSPEND_REPAIR.getState())) {
                if (pwo.getState().equals(EnumPatrolState.SUSPEND_REPAIR.getState())) {
                    insertFlowAdd(id, 3, 0, li.getLoginEmployeeId(), "", date);
                } else {
                    pwo.setRoStartTime(date);
                    insertFlow(id, 3, 0, li.getLoginEmployeeId(), "", date);
                }
                state = EnumPatrolState.UNDE_REPAIR.getState();
            } else {
                return DataResult.build9250("待巡检的巡检单才能开工");
            }
        } else if (operation == 4) {
            if (!pwo.getState().equals(EnumPatrolState.UNDE_REPAIR.getState())) {
                return DataResult.build9250("巡检中的工单才能完成");
            }
            state = EnumPatrolState.ACCEPTED_YES.getState();
            PatrolWorkOrderFlowExample pwofExample = new PatrolWorkOrderFlowExample();
            PatrolWorkOrderFlowExample.Criteria pwofCriteria = pwofExample.createCriteria();
            pwofCriteria.andPatrolIdEqualTo(id);
            pwofCriteria.andIsSynEqualTo(0);
            //查询巡检暂停时间
            pwofCriteria.andFlowTypeEqualTo(3);
            pwofExample.setOrderByClause("create_time");
            List<PatrolWorkOrderFlow> pwfsList = patrolWorkOrderFlowMapper.selectByExample(pwofExample);
            long pauseSecond = 0L;
            for (PatrolWorkOrderFlow pwof : pwfsList) {
                if (pwof.getPauseTimeSecond() != null) {
                    pauseSecond += pwof.getPauseTimeSecond();
                }
            }
            pwo.setEndTime(date);
            //工单时长
            if (pwo.getCreateTime() != null) {
                int orderDuration = (int) DateUtil.between(pwo.getCreateTime(), date, DateUnit.MINUTE);
                pwo.setOrderDuration(orderDuration);
            }
            //巡检时长
            if (pwo.getRoStartTime() != null) {
                long between = DateUtil.between(pwo.getRoStartTime(), date, DateUnit.SECOND);
                long orderWorkSecond = between - pauseSecond;
                int orderWorkHour = (int) orderWorkSecond / 60;
                pwo.setOrderWorkHour(orderWorkHour);
            }
            insertFlow(id, 4, 0, li.getLoginEmployeeId(), "", date);

            for (long userId : commonService.selectManagerUserIdList(4)) {
                commonService.insertMessageBacklog(
                        userId,
                        "巡检单【" + pwo.getCode() + "】已巡检完工，请审核",
                        "巡检单【" + pwo.getCode() + "】已巡检完成，请审核评价。",
                        4, 3, pwo.getId(), pwo.getCode()
                );
            }

        } else if (operation == 5) {
            if (!pwo.getState().equals(EnumPatrolState.ACCEPTED_YES.getState())) {
                return DataResult.build9250("待验收巡检单才能验收");
            }
            //验收状态;1,通过;2，驳回
            if (StrUtil.isBlank(acceptState)) {
                return DataResult.build9250("acceptState不能为空!");
            }

            if (acceptState.equals("1")) {
                if (!NumberUtil.isNumber(acceptScore)) {
                    return DataResult.build9250("评分必须输入数字!");
                }
                state = EnumPatrolState.MAINTENANCE_YES.getState();
                BusinessAccept newBa = new BusinessAccept();
                newBa.setSourceId(id);
                newBa.setBusType(5);
                newBa.setAcceptState(1);
                newBa.setEmployeeId(li.getLoginEmployeeId());
                newBa.setBusEmployeeId(pwo.getPatrolEmployeeId());
                newBa.setAcceptExplain(StrUtil.isBlank(operationInfo) ? "" : operationInfo);
                newBa.setAcceptScore(new BigDecimal(acceptScore));
                newBa.setAcceptTime(date);
                newBa.setCreateTime(date);
                businessAcceptMapper.insert(newBa);

                insertFlow(id, 5, 0, li.getLoginEmployeeId(), StrUtil.isBlank(operationInfo) ? "" : operationInfo, date);

                commonService.insertMessageInform(
                        pwo.getPatrolEmployeeId(),
                        "巡检单【" + pwo.getCode() + "】已审核完成",
                        "巡检单【" + pwo.getCode() + "】已审核完成，巡检打分：【" + acceptScore + "】分。巡检评价：【" + operationInfo + "】",
                        4, 4, pwo.getId(), pwo.getCode()
                );
            } else {
                state = EnumPatrolState.ALLOCATED.getState();
                pwo.setRoStartTime(null);
                pwo.setEndTime(null);
                pwo.setOrderDuration(null);
                pwo.setOrderWorkHour(null);
                BusinessAccept newBa = new BusinessAccept();
                newBa.setSourceId(id);
                newBa.setBusType(5);
                newBa.setAcceptState(2);
                newBa.setEmployeeId(li.getLoginEmployeeId());
                newBa.setBusEmployeeId(pwo.getPatrolEmployeeId());
                newBa.setAcceptExplain(StrUtil.isBlank(operationInfo) ? "" : operationInfo);
                newBa.setAcceptScore(BigDecimal.ZERO);
                newBa.setAcceptTime(date);
                newBa.setCreateTime(date);
                businessAcceptMapper.insert(newBa);

                insertFlowTransfer(id, 7, 0, li.getLoginEmployeeId(), StrUtil.isBlank(operationInfo) ? "" : operationInfo, date);

                commonService.insertMessageInform(
                        pwo.getPatrolEmployeeId(),
                        "巡检单【" + pwo.getCode() + "】已审核驳回",
                        "巡检单【" + pwo.getCode() + "】已审核驳回，巡检评价：【" + operationInfo + "】",
                        4, 4, pwo.getId(), pwo.getCode()
                );
            }
        } else if (operation == 6) {
            if (!pwo.getState().equals(EnumPatrolState.UNDE_REPAIR.getState())) {
                return DataResult.build9250("巡检单当前状态已不可暂停");
            }
            state = EnumPatrolState.SUSPEND_REPAIR.getState();
            insertFlow(id, 6, 0, li.getLoginEmployeeId(), StrUtil.isBlank(operationInfo) ? "" : operationInfo, date);
        }
        pwo.setState(state);
        patrolWorkOrderMapper.updateByPrimaryKey(pwo);
        return DataResult.build9100();
    }

    @Override
    public DataResult updatePatrolTaskState(LoginInfo li, long id, int state) throws Exception {
        PatrolTree pt = patrolTreeMapper.selectByPrimaryKey(id);
        PatrolWorkOrder pwo = patrolWorkOrderMapper.selectByPrimaryKey(pt.getPatrolId());
        if (!pwo.getState().equals(EnumPatrolState.UNDE_REPAIR.getState())) {
            return DataResult.build9250("巡检中的工单才能编辑");
        }
        PatrolTree newPt = new PatrolTree();
        newPt.setId(id);
        newPt.setState(state);
        patrolTreeMapper.updateByPrimaryKeySelective(newPt);
        return DataResult.build9100();
    }

    @Override
    public DataResult updatePatrolTaskStateList(
            LoginInfo li,
            List<PatrolTaskStateListDto> dtoList
    ) throws Exception {
        if(dtoList == null || dtoList.isEmpty()){
            return DataResult.build9250("巡检中的工单才能编辑");
        }
        for(PatrolTaskStateListDto dto : dtoList){

            PatrolTree pt = patrolTreeMapper.selectByPrimaryKey(dto.getId());
            PatrolWorkOrder pwo = patrolWorkOrderMapper.selectByPrimaryKey(pt.getPatrolId());
            if (!pwo.getState().equals(EnumPatrolState.UNDE_REPAIR.getState())) {
                return DataResult.build9250("巡检中的工单才能编辑");
            }
            PatrolTree newPt = new PatrolTree();
            newPt.setId(dto.getId());
            newPt.setState(dto.getState());
            patrolTreeMapper.updateByPrimaryKeySelective(newPt);

            if(dto.getState() == 2 && dto.getTaskList() != null && !dto.getTaskList().isEmpty()){
                for(PatrolTaskStateListSubDto subDto : dto.getTaskList()){
                    updatePatrolTask(li,subDto.getId(),subDto.getState() == 1 ? 2 : subDto.getState(),"");
                }
            }
        }
        return DataResult.build9100();
    }

    @Override
    public DataResult updatePatrolTask(LoginInfo li, long id, int state, String recordedValue) throws Exception {
        PatrolTreeTask ptt = patrolTreeTaskMapper.selectByPrimaryKey(id);
        PatrolTree pt = patrolTreeMapper.selectByPrimaryKey(ptt.getPatrolTreeId());
        PatrolWorkOrder pwo = patrolWorkOrderMapper.selectByPrimaryKey(pt.getPatrolId());
        if (!pwo.getState().equals(EnumPatrolState.UNDE_REPAIR.getState())) {
            return DataResult.build9250("巡检中的工单才能编辑");
        }
        if (state == 3) {
            PatrolWorkOrder newPwo = new PatrolWorkOrder();
            newPwo.setId(pt.getPatrolId());
            newPwo.setIsException(1);
            patrolWorkOrderMapper.updateByPrimaryKeySelective(newPwo);
        }
        PatrolTreeTask newPtt = new PatrolTreeTask();
        newPtt.setId(id);
        newPtt.setState(state);
        newPtt.setRecordedValue(recordedValue);
        patrolTreeTaskMapper.updateByPrimaryKeySelective(newPtt);
        return DataResult.build9100();
    }

    @Override
    public DataResult updatePatrolDetail(LoginInfo li, long id, String orderException, String filePicCode, String fileAudioCode, String fileVideoCode) throws Exception {
        PatrolWorkOrder pwo = patrolWorkOrderMapper.selectByPrimaryKey(id);
        if (pwo.getState() >= 4) {
            return DataResult.build9250("巡检单当前状态已不可编辑");
        }
        pwo.setOrderException(orderException);
        patrolWorkOrderMapper.updateByPrimaryKey(pwo);

        BusinessFileExample bfExample = new BusinessFileExample();
        bfExample.createCriteria().andBusTypeEqualTo(8).andFileGroupEqualTo(1).andBusTablesIdEqualTo(pwo.getId());
        businessFileMapper.deleteByExample(bfExample);

        Date date = new Date();
        BusinessFile newBf = new BusinessFile();
        newBf.setBusTablesId(id);
        newBf.setBusType(8);
        newBf.setFileGroup(1);
        newBf.setEmployeeId(li.getLoginEmployeeId());
        newBf.setUpdateTime(date);
        newBf.setCreateTime(date);
        newBf.setFileType(1);
        if (StrUtil.isNotBlank(filePicCode)) {
            for (String fileCode : filePicCode.split(",")) {
                newBf.setFileCode(fileCode);
                businessFileMapper.insert(newBf);
            }
        }
        newBf.setFileType(2);
        if (StrUtil.isNotBlank(fileAudioCode)) {
            for (String fileCode : fileAudioCode.split(",")) {
                newBf.setFileCode(fileCode);
                businessFileMapper.insert(newBf);
            }
        }
        newBf.setFileType(3);
        if (StrUtil.isNotBlank(fileVideoCode)) {
            for (String fileCode : fileVideoCode.split(",")) {
                newBf.setFileCode(fileCode);
                businessFileMapper.insert(newBf);
            }
        }
        return DataResult.build9100();
    }

    @Override
    public DataResult updatePatrolDispose(
            LoginInfo li, long id,
            String faultType, String faultReason, String emState, String disposeResult,
            String fileOldPicCode, String fileOldAudioCode, String fileOldVideoCode,
            String fileNewPicCode, String fileNewAudioCode, String fileNewVideoCode
    ) throws Exception {
        PatrolWorkOrder pwo = patrolWorkOrderMapper.selectByPrimaryKey(id);
        if (pwo.getState() >= 4) {
            return DataResult.build9250("巡检单当前状态已不可编辑");
        }
        pwo.setFaultType(StrUtil.isBlank(faultType) ? null : Long.parseLong(faultType));
        pwo.setFaultReason(StrUtil.isBlank(faultReason) ? null : Long.parseLong(faultReason));
        pwo.setEmState(StrUtil.isBlank(emState) ? null : Long.parseLong(emState));
        pwo.setDisposeResult(disposeResult);
        patrolWorkOrderMapper.updateByPrimaryKey(pwo);

        BusinessFileExample bfExample = new BusinessFileExample();
        bfExample.createCriteria().andBusTypeEqualTo(8).andFileGroupIn(Arrays.asList(2, 3)).andBusTablesIdEqualTo(pwo.getId());
        businessFileMapper.deleteByExample(bfExample);

        Date date = new Date();
        BusinessFile newBf = new BusinessFile();
        newBf.setBusTablesId(id);
        newBf.setBusType(8);
        newBf.setEmployeeId(li.getLoginEmployeeId());
        newBf.setUpdateTime(date);
        newBf.setCreateTime(date);

        newBf.setFileGroup(2);
        newBf.setFileType(1);
        if (StrUtil.isNotBlank(fileOldPicCode)) {
            for (String fileCode : fileOldPicCode.split(",")) {
                newBf.setFileCode(fileCode);
                businessFileMapper.insert(newBf);
            }
        }

        newBf.setFileType(2);

        if (StrUtil.isNotBlank(fileOldAudioCode)) {
            for (String fileCode : fileOldAudioCode.split(",")) {
                newBf.setFileCode(fileCode);
                businessFileMapper.insert(newBf);
            }
        }
        newBf.setFileType(3);

        if (StrUtil.isNotBlank(fileOldVideoCode)) {
            for (String fileCode : fileOldVideoCode.split(",")) {
                newBf.setFileCode(fileCode);
                businessFileMapper.insert(newBf);
            }
        }

        newBf.setFileGroup(3);
        newBf.setFileType(1);

        if (StrUtil.isNotBlank(fileNewPicCode)) {
            for (String fileCode : fileNewPicCode.split(",")) {
                newBf.setFileCode(fileCode);
                businessFileMapper.insert(newBf);
            }
        }
        newBf.setFileType(2);
        if (StrUtil.isNotBlank(fileNewAudioCode)) {
            for (String fileCode : fileNewAudioCode.split(",")) {
                newBf.setFileCode(fileCode);
                businessFileMapper.insert(newBf);
            }
        }
        newBf.setFileType(3);
        if (StrUtil.isNotBlank(fileNewVideoCode)) {
            for (String fileCode : fileNewVideoCode.split(",")) {
                newBf.setFileCode(fileCode);
                businessFileMapper.insert(newBf);
            }
        }
        return DataResult.build9100();
    }

    public String getPatrolCode(Date date) throws Exception {
        String format = DateUtil.format(date, DatePattern.PURE_DATE_FORMATTER);
        SystemParameter sp = systemParameterMapper.selectByPrimaryKey(SystemData.PATROL_WORK_NUMBER);
        int num = Integer.parseInt(sp.getParameterValue()) + 1;
        String code;
        if (num < 10) {
            code = "000" + num;
        } else if (num < 100) {
            code = "00" + num;
        } else if (num < 1000) {
            code = "0" + num;
        } else {
            code = "" + num;
        }
        sp.setParameterValue(num + "");
        systemParameterMapper.updateByPrimaryKey(sp);
        return "XJ" + format + code;
    }

    public void insertFlow(
            long patrolId, int flowType, long sourceId,
            long employeeId, String flowDesc, Date date
    ) {
        PatrolWorkOrderFlow newPwof = new PatrolWorkOrderFlow();
        newPwof.setPatrolId(patrolId);
        newPwof.setPlanId(0L);
        newPwof.setFlowType(flowType);
        newPwof.setSourceId(sourceId);
        newPwof.setEmployeeId(employeeId);
        newPwof.setFlowDesc(flowDesc);
        newPwof.setCreateTime(date);
        newPwof.setIsSyn(0);
        patrolWorkOrderFlowMapper.insertSelective(newPwof);
    }

    public void insertFlowAdd(
            long patrolId, int flowType, long sourceId,
            long employeeId, String flowDesc, Date date
    ) {
        Long pauseTimeSecond = 0L;
        PatrolWorkOrderFlowExample pwofExample = new PatrolWorkOrderFlowExample();
        PatrolWorkOrderFlowExample.Criteria pwofCriteria = pwofExample.createCriteria();
        pwofCriteria.andPatrolIdEqualTo(patrolId);
        //查询巡检暂停时间
        pwofCriteria.andFlowTypeEqualTo(6);
        pwofExample.setOrderByClause("create_time desc limit 1");
        List<PatrolWorkOrderFlow> pwfsList = patrolWorkOrderFlowMapper.selectByExample(pwofExample);
        if (CollUtil.isNotEmpty(pwfsList)) {
            pauseTimeSecond = DateUtil.between(pwfsList.get(0).getCreateTime(), date, DateUnit.SECOND);
        }
        PatrolWorkOrderFlow newPwof = new PatrolWorkOrderFlow();
        newPwof.setPatrolId(patrolId);
        newPwof.setPlanId(0L);
        newPwof.setFlowType(flowType);
        newPwof.setSourceId(sourceId);
        newPwof.setEmployeeId(employeeId);
        newPwof.setFlowDesc(flowDesc);
        newPwof.setCreateTime(date);
        newPwof.setIsSyn(0);
        newPwof.setPauseTimeSecond(pauseTimeSecond);
        patrolWorkOrderFlowMapper.insertSelective(newPwof);
    }

    /*
     * 转交时候打标识
     * */
    public void insertFlowTransfer(
            long patrolId, int flowType, long sourceId, long employeeId,
            String flowDesc, Date date
    ) {
        PatrolWorkOrderFlow newPwof = new PatrolWorkOrderFlow();
        newPwof.setPatrolId(patrolId);
        newPwof.setPlanId(0L);
        newPwof.setFlowType(flowType);
        newPwof.setSourceId(sourceId);
        newPwof.setEmployeeId(employeeId);
        newPwof.setFlowDesc(flowDesc);
        newPwof.setCreateTime(date);
        newPwof.setIsSyn(0);
        patrolWorkOrderFlowMapper.insert(newPwof);

        PatrolWorkOrderFlow updateFlow = new PatrolWorkOrderFlow();
        updateFlow.setIsSyn(1);
        PatrolWorkOrderFlowExample example = new PatrolWorkOrderFlowExample();
        PatrolWorkOrderFlowExample.Criteria criteria = example.createCriteria();
        criteria.andPatrolIdEqualTo(patrolId);
        criteria.andFlowTypeEqualTo(3);
        patrolWorkOrderFlowMapper.updateByExampleSelective(updateFlow, example);
    }

    /*
     * 巡检领取巡检
     * */
    @Override
    public DataResult receivePatrol(LoginInfo loginInfo, String id) throws Exception {
        PatrolWorkOrder getPatrolWorkOrder = patrolWorkOrderMapper.selectByPrimaryKey(Long.parseLong(id));
        if (getPatrolWorkOrder == null) {
            return DataResult.build9250("获取巡检工单信息失败！");
        }
        if (!getPatrolWorkOrder.getState().equals(EnumPatrolState.PENDING_RECEIVE.getState())) {
            return DataResult.build9250("只有待领取状态的巡检工单才能领取！！");
        }
        Date date = new Date();
        //修改维修单状态
        PatrolWorkOrder patrolWorkOrder = new PatrolWorkOrder();
        patrolWorkOrder.setId(Long.parseLong(id));
        patrolWorkOrder.setState(EnumPatrolState.ALLOCATED.getState());
        patrolWorkOrder.setPatrolEmployeeId(loginInfo.getLoginEmployeeId());
        if (getPatrolWorkOrder.getAssStartTime() == null) {
            patrolWorkOrder.setAssStartTime(date);
        }
        patrolWorkOrderMapper.updateByPrimaryKeySelective(patrolWorkOrder);

        insertFlow(Long.parseLong(id), 8, 0, loginInfo.getLoginEmployeeId(), "", date);

        //待办
        EquipmentTree tree3 = equipmentTreeMapper.selectByPrimaryKey(getPatrolWorkOrder.getTreeId());
        EquipmentTree tree2 = equipmentTreeMapper.selectByPrimaryKey(tree3.getBaseId());
        EquipmentTree tree1 = equipmentTreeMapper.selectByPrimaryKey(tree2.getBaseId());

        commonService.insertMessageBacklog(
                loginInfo.getLoginEmployeeId(),
                "【" + getPatrolWorkOrder.getCode() + "】巡检单已分配到您，请处理",
                "【" + getPatrolWorkOrder.getCode() + "】已分配到您，巡检区域：【" + tree1.getName() + "-" + tree2.getName() + "-" + tree3.getName() + "】，请尽快到场处理。",
                4, 1, getPatrolWorkOrder.getId(), getPatrolWorkOrder.getCode()
        );
        return DataResult.build9100();
    }

    /*
     * 巡检工单转交
     * */
    @Override
    public DataResult transferPatrol(LoginInfo loginInfo, String id) throws Exception {
        PatrolWorkOrder getPatrolWorkOrder = patrolWorkOrderMapper.selectByPrimaryKey(Long.parseLong(id));
        if (getPatrolWorkOrder == null) {
            return DataResult.build9250("获取巡检工单信息失败！");
        }
        if (!getPatrolWorkOrder.getState().equals(EnumPatrolState.ALLOCATED.getState())) {
            return DataResult.build9250("只有待巡检状态的巡检工单才能转交！！");
        }
        //修改维修单状态
        getPatrolWorkOrder.setState(EnumPatrolState.PENDING_RECEIVE.getState());
        getPatrolWorkOrder.setPatrolEmployeeId(0L);
        getPatrolWorkOrder.setRoStartTime(null);
        patrolWorkOrderMapper.updateByPrimaryKey(getPatrolWorkOrder);
        insertFlowTransfer(Long.parseLong(id), 9, 0, loginInfo.getLoginEmployeeId(), "", new Date());
        return DataResult.build9100();
    }

    @Override
    public DataResult nullifyPatrol(LoginInfo loginInfo, String id) throws Exception {
        PatrolWorkOrder getPatrolWorkOrder = patrolWorkOrderMapper.selectByPrimaryKey(Long.parseLong(id));
        List<String> loginRoleDirectoryMarkList = loginInfo.getLoginRoleDirectoryMarkList();
        if (CollUtil.isNotEmpty(loginRoleDirectoryMarkList)) {
            if (!loginRoleDirectoryMarkList.contains("PATROL_CANCELLATION")) {
                return DataResult.build9250("没有权限作废！");
            }
        } else {
            return DataResult.build9250("没获取到权限！");
        }
        if (getPatrolWorkOrder == null) {
            return DataResult.build9250("获取巡检工单信息失败！");
        }
        if (!getPatrolWorkOrder.getState().equals(EnumPatrolState.PENDING_RECEIVE.getState()) && !getPatrolWorkOrder.getState().equals(EnumPatrolState.ALLOCATED.getState())) {
            return DataResult.build9250("没开工的巡检单才能废除！！");
        }
        PatrolWorkOrder updateWorkOrder = new PatrolWorkOrder();
        updateWorkOrder.setState(-1);
        updateWorkOrder.setId(getPatrolWorkOrder.getId());
        patrolWorkOrderMapper.updateByPrimaryKeySelective(updateWorkOrder);
        insertFlowTransfer(Long.parseLong(id), 10, 0, loginInfo.getLoginEmployeeId(), "", new Date());
        if(getPatrolWorkOrder.getState().equals(EnumPatrolState.ALLOCATED.getState())){
            commonService.insertMessageInform(
                    getPatrolWorkOrder.getPatrolEmployeeId(),
                    "巡检单【" + getPatrolWorkOrder.getCode() + "】已废除",
                    "巡检单【" + getPatrolWorkOrder.getCode() + "】已废除",
                    4, 5, getPatrolWorkOrder.getId(), getPatrolWorkOrder.getCode()
            );
        }
        return DataResult.build9100();
    }

    public void insertTask(
            long patrolId, long treeId
    ) {

        int index = 0;

        EquipmentTreeExample etExample = new EquipmentTreeExample();
        etExample.createCriteria().andBaseIdEqualTo(treeId);
        etExample.setOrderByClause("sort");
        List<EquipmentTree> etList = equipmentTreeMapper.selectByExample(etExample);
        for (EquipmentTree et : etList) {
            if (et.getEmType() == 0) {
                continue;
            }
            PatrolTemplateTaskExample ttExample = new PatrolTemplateTaskExample();
            ttExample.createCriteria().andTypeEqualTo(1).andEmTypeEqualTo(et.getEmType());
            ttExample.setOrderByClause("sort");
            List<PatrolTemplateTask> ttList = patrolTemplateTaskMapper.selectByExample(ttExample);
            if (ttList.size() == 0) {
                continue;
            }

            PatrolTree newPt = new PatrolTree();
            newPt.setPatrolId(patrolId);
            newPt.setType(1);
            newPt.setTypeId(et.getId());
            newPt.setState(2);
            newPt.setEmType(et.getEmType());
            newPt.setSort(index++);
            patrolTreeMapper.insert(newPt);

            for (PatrolTemplateTask tt : ttList) {
                PatrolTreeTask newPtt = new PatrolTreeTask();
                newPtt.setPatrolTreeId(newPt.getId());
                newPtt.setTaskId(tt.getId());
                newPtt.setState(1);
                newPtt.setIsRecorded(tt.getIsRecorded());
                newPtt.setSort(tt.getSort());
                patrolTreeTaskMapper.insert(newPtt);
            }
        }
        EquipmentInfoExample eiExample = new EquipmentInfoExample();
        eiExample.createCriteria().andEmTreeEqualTo(treeId);
        List<EquipmentInfo> eiList = equipmentInfoMapper.selectByExample(eiExample);
        for (EquipmentInfo ei : eiList) {
            if (ei.getEmType() == 0) {
                continue;
            }
            PatrolTemplateTaskExample ttExample = new PatrolTemplateTaskExample();
            ttExample.createCriteria().andTypeEqualTo(1).andEmTypeEqualTo(ei.getEmType());
            ttExample.setOrderByClause("sort");
            List<PatrolTemplateTask> ttList = patrolTemplateTaskMapper.selectByExample(ttExample);
            if (ttList.size() == 0) {
                continue;
            }

            PatrolTree newPt = new PatrolTree();
            newPt.setPatrolId(patrolId);
            newPt.setType(2);
            newPt.setTypeId(ei.getId());
            newPt.setState((ei.getEmState() == 4 || ei.getEmState() == 5) ? 1 : 2);
            newPt.setEmType(ei.getEmType());
            newPt.setSort(index++);
            patrolTreeMapper.insert(newPt);

            for (PatrolTemplateTask tt : ttList) {
                PatrolTreeTask newPtt = new PatrolTreeTask();
                newPtt.setPatrolTreeId(newPt.getId());
                newPtt.setTaskId(tt.getId());
                newPtt.setState(1);
                newPtt.setIsRecorded(tt.getIsRecorded());
                newPtt.setSort(tt.getSort());
                patrolTreeTaskMapper.insert(newPtt);
            }
        }
        PatrolTemplateSubsystemExample subsystemExample = new PatrolTemplateSubsystemExample();
        subsystemExample.createCriteria().andSubsystemTreeIdEqualTo(treeId);
        List<PatrolTemplateSubsystem> patrolTemplateSubsystems = patrolTemplateSubsystemMapper.selectByExample(subsystemExample);
        for (PatrolTemplateSubsystem patrolTemplateSubsystem : patrolTemplateSubsystems) {
            PatrolTemplateTaskExample pttExample = new PatrolTemplateTaskExample();
            pttExample.createCriteria().andTypeEqualTo(2).andSubsystemIdEqualTo(patrolTemplateSubsystem.getId());
            pttExample.setOrderByClause("sort");
            List<PatrolTemplateTask> pttList = patrolTemplateTaskMapper.selectByExample(pttExample);

            PatrolTree newPt = new PatrolTree();
            newPt.setPatrolId(patrolId);
            newPt.setType(3);
            newPt.setTypeId(patrolTemplateSubsystem.getId());
            newPt.setState(2);
            newPt.setEmType(0);
            newPt.setSort(index++);
            patrolTreeMapper.insert(newPt);
            for (PatrolTemplateTask tt : pttList) {
                PatrolTreeTask newPtt = new PatrolTreeTask();
                newPtt.setPatrolTreeId(newPt.getId());
                newPtt.setTaskId(tt.getId());
                newPtt.setState(1);
                newPtt.setIsRecorded(tt.getIsRecorded());
                newPtt.setSort(tt.getSort());
                patrolTreeTaskMapper.insert(newPtt);
            }
        }
    }

    @Override
    public Map<String, Object> getInfoWord(LoginInfo loginInfo,String objId) {
        //查询巡检基本信息数据
        PatrolWorkOrder patrolWorkOrder = patrolWorkOrderMapper.selectByPrimaryKey(Long.valueOf(objId));
        PatrolWorkOrder infoWordVo = ConvertVoUtil.nullToStringBean(patrolWorkOrder);
//        DateUtil.formatDateTime(infoWordVo.getStartTime(), "yyyy年MM月dd日");
//        InfoWordVo WordVo = new InfoWordVo();
//        Map<String, Object> map = BeanUtil.beanToMap(WordVo, new HashMap<>(), false, true);
        //查询设备list列表数据
        return null;
    }

}
